﻿<UserControl x:Class="SupremacyEditor.LocalizedTextEditor"
             x:Name="Editor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:s="http://www.startreksupremacy.com/"
             xmlns:scc="http://www.startreksupremacy.com/scc"
             xmlns:apribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
             xmlns:apthemes="http://schemas.actiprosoftware.com/winfx/xaml/themes"
             xmlns:apshared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
             xmlns:apeditors="http://schemas.actiprosoftware.com/winfx/xaml/editors"
             xmlns:local="clr-namespace:SupremacyEditor"
             MinWidth="200"
             SnapsToDevicePixels="True">
  <UserControl.Resources>
    <local:LanguageToFlagImageSourceConverter x:Key="LanguageToFlagImageSourceConverter" />
  </UserControl.Resources>
  <DockPanel LastChildFill="True">
    <apribbon:PopupButton DockPanel.Dock="Right"
                          TabIndex="1"
                          PopupHasBorder="True"
                          PopupPlacement="Bottom"
                          PopupVerticalOffset="1"
                          VerticalAlignment="Top"
                          Margin="3,0,0,0"
                          RenderOptions.BitmapScalingMode="NearestNeighbor"
                          ImageSourceSmall="{Binding Path=Language, Converter={StaticResource LanguageToFlagImageSourceConverter}, Mode=OneWay}"
                          VariantSize="Small"
                          SnapsToDevicePixels="True">
      <apribbon:PopupButton.PopupContent>
        <Border Padding="7"
                Width="480"
                Height="320"
                Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
          <DockPanel LastChildFill="True">
            <ListBox x:Name="EntryList"
                     DockPanel.Dock="Left"
                     Width="160"
                     Margin="0,0,6,0"
                     ItemsSource="{Binding}"
                     IsSynchronizedWithCurrentItem="True">
              <ListBox.Resources>
                <Style TargetType="ListBoxItem">
                  <Setter Property="FocusVisualStyle"
                          Value="{x:Null}" />
                  <Setter Property="Template">
                    <Setter.Value>
                      <ControlTemplate TargetType="ListBoxItem">
                        <Border x:Name="OuterBorder"
                                Margin="2,2,2,0"
                                BorderThickness="1"
                                CornerRadius="3"
                                BorderBrush="Transparent"
                                Background="Transparent">
                          <Border x:Name="InnerBorder"
                                  BorderThickness="1"
                                  CornerRadius="2"
                                  BorderBrush="Transparent"
                                  Background="Transparent">
                            <ContentPresenter x:Name="Content"
                                              Margin="10,3,10,3" />
                          </Border>
                        </Border>
                        <ControlTemplate.Triggers>
                          <Trigger Property="IsEnabled"
                                   Value="False">
                            <Setter TargetName="OuterBorder"
                                    Property="BorderThickness"
                                    Value="0" />
                            <Setter TargetName="InnerBorder"
                                    Property="BorderThickness"
                                    Value="0" />
                            <Setter TargetName="Content"
                                    Property="Margin"
                                    Value="0" />
                          </Trigger>
                          <Trigger Property="IsMouseOver"
                                   Value="True">
                            <Setter TargetName="OuterBorder"
                                    Property="BorderBrush"
                                    Value="{DynamicResource {x:Static apthemes:RibbonCommonDictionary.RibbonControlOuterBorderHoverBrushKey}}" />
                            <Setter TargetName="OuterBorder"
                                    Property="Background"
                                    Value="{DynamicResource {x:Static apthemes:RibbonCommonDictionary.RibbonControlLargeBackgroundHoverBrushKey}}" />
                            <Setter TargetName="InnerBorder"
                                    Property="BorderBrush"
                                    Value="{DynamicResource {x:Static apthemes:RibbonCommonDictionary.RibbonControlInnerBorderHoverBrushKey}}" />
                          </Trigger>
                          <MultiTrigger>
                            <MultiTrigger.Conditions>
                              <Condition Property="IsSelected"
                                         Value="True" />
                              <Condition Property="IsMouseOver"
                                         Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="OuterBorder"
                                    Property="BorderBrush"
                                    Value="{DynamicResource {x:Static apthemes:RibbonCommonDictionary.RibbonControlOuterBorderSelectedBrushKey}}" />
                            <Setter TargetName="OuterBorder"
                                    Property="Background"
                                    Value="{DynamicResource {x:Static apthemes:RibbonCommonDictionary.RibbonControlLargeBackgroundSelectedBrushKey}}" />
                            <Setter TargetName="InnerBorder"
                                    Property="BorderBrush"
                                    Value="{DynamicResource {x:Static apthemes:RibbonCommonDictionary.RibbonControlInnerBorderSelectedBrushKey}}" />
                          </MultiTrigger>
                          <MultiTrigger>
                            <MultiTrigger.Conditions>
                              <Condition Property="IsSelected"
                                         Value="True" />
                              <Condition Property="IsMouseOver"
                                         Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="OuterBorder"
                                    Property="BorderBrush"
                                    Value="{DynamicResource {x:Static apthemes:RibbonCommonDictionary.RibbonControlOuterBorderHoverSelectedBrushKey}}" />
                            <Setter TargetName="OuterBorder"
                                    Property="Background"
                                    Value="{DynamicResource {x:Static apthemes:RibbonCommonDictionary.RibbonControlLargeBackgroundHoverSelectedBrushKey}}" />
                            <Setter TargetName="InnerBorder"
                                    Property="BorderBrush"
                                    Value="{DynamicResource {x:Static apthemes:RibbonCommonDictionary.RibbonControlInnerBorderHoverSelectedBrushKey}}" />
                          </MultiTrigger>
                        </ControlTemplate.Triggers>
                      </ControlTemplate>
                    </Setter.Value>
                  </Setter>
                </Style>
              </ListBox.Resources>
              <ListBox.ItemTemplate>
                <DataTemplate DataType="{x:Type s:ILocalizedTextDatabaseEntry}">
                  <StackPanel Orientation="Horizontal">
                    <Image Stretch="None"
                           Width="16"
                           Height="11"
                           Source="{Binding Path=Language, Converter={StaticResource LanguageToFlagImageSourceConverter}, Mode=OneWay}"
                           VerticalAlignment="Center"
                           RenderOptions.BitmapScalingMode="NearestNeighbor" />
                    <TextBlock Margin="5,0,0,0"
                               VerticalAlignment="Center"
                               Text="{Binding Path=LanguageName}" />
                  </StackPanel>
                </DataTemplate>
              </ListBox.ItemTemplate>
            </ListBox>
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
              </Grid.RowDefinitions>
              <TextBox x:Name="EntryText"
                       Grid.Row="0"
                       SpellCheck.IsEnabled="{Binding Path=SpellCheck.IsEnabled, ElementName=Editor, Mode=OneWay}"
                       AcceptsReturn="{Binding Path=AcceptsReturn, ElementName=Editor, Mode=OneWay}"
                       VerticalContentAlignment="Top"
                       TextWrapping="Wrap" />
              <Grid Grid.Row="1"
                    Height="24"
                    Margin="0,6,0,0">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <apribbon:Button x:Name="AcceptButton"
                                 Context="RibbonTabGroup"
                                 Grid.Column="0"
                                 Click="AcceptButton_Click"
                                 Label="Save" />
                <apribbon:Button x:Name="CancelButton"
                                 Context="RibbonTabGroupItem"
                                 Grid.Column="1"
                                 Click="CancelButton_Click"
                                 Margin="6,0,0,0"
                                 HorizontalAlignment="Left"
                                 Label="Cancel" />
              </Grid>
            </Grid>
          </DockPanel>
        </Border>
      </apribbon:PopupButton.PopupContent>
    </apribbon:PopupButton>
    <apshared:PixelSnapper>
      <TextBox x:Name="LocalTextEditor"
               Text="{Binding Path=LocalText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:LocalizedTextEditor}}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
               AcceptsReturn="{Binding Path=AcceptsReturn, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:LocalizedTextEditor}}, Mode=OneWay}"
               TextWrapping="{Binding Path=TextWrapping, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:LocalizedTextEditor}}, Mode=OneWay}"
               VerticalScrollBarVisibility="{Binding Path=VerticalScrollBarVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:LocalizedTextEditor}}, Mode=OneWay}"
               TabIndex="0" />
    </apshared:PixelSnapper>
  </DockPanel>
</UserControl>
